package org.example.exception;

import org.example.common.ResultData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author itmei
 * @Date 2023/12/20 20:58
 * @description: 全局异常捕获类
 * @Title: GlobalExceptionHandler
 * @Package com.itmei.cicddemo.demos.exception
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
    /**
     * 全局异常
     */
    @ExceptionHandler(Exception.class)
    public ResultData handleException(Exception e, HttpServletRequest request)
    {
        String requestURI = request.getRequestURI();
        log.error("请求地址'{}',发生系统异常.", requestURI, e);
        return ResultData.error(e.getMessage());
    }
}


